package algorithm;

import java.util.Collections;
import java.util.Iterator;

import objects.Mobile;
import objects.Station;
import manager.Manager;

public class algorithm {
	
	public static void compute()
	{
		 Collections.sort(Manager.ListMobile);

		Iterator<Mobile> j = Manager.ListMobile.iterator();
		int i=0;
		int tampon = Station.numberSubcarrier;
		Manager.numbersubcarrieravailable=tampon;
		while(j.hasNext())
		{
			
			float least_common_multiple=(Manager.numbersubcarrieravailable/12)/(Manager.ListMobile.size()-i);
			Mobile phone=j.next();
			if(phone.getNbTweSubNeed()<least_common_multiple)
			{
				phone.setReceivedFrequency((int)phone.getNbTweSubNeed());
				phone.setBandWidthGot(Manager.convertNbTweSubNeedToBandwidth(phone.getReceivedFrequency()));

			}
			else
			{
				phone.setReceivedFrequency((int) Math.floor(least_common_multiple));
				phone.setBandWidthGot(Manager.convertNbTweSubNeedToBandwidth(phone.getReceivedFrequency()));
			}
			Manager.subcarrierRequested-=phone.getNbTweSubNeed();
			Manager.numbersubcarrieravailable-=phone.getReceivedFrequency()*12;
			i++;
		}
	}
}
	/*
	}
	total number of sub-carrier+Time slot available
	For each modification of the number of the phone
	do
	if  total number of freq sub-carrier requested < number of available sub-carrier then
		all phone are satisfied
	else
		least common multiple = total number of sub-carrier requested / number of phone on the cell
		short phone according to their demand of number  sub-carrier
		For I =1  to total number of phone
			if number of frequency requested[I] <  least common multiple
				give all frequency requested by I
				number of sub-carrier available -= number of sub-carrier requested by I
			else
				take the inferior integer of the least common multiple
				number of sub-carrier available -= inferior integer of the least common multiple
			end if
		end for
	end if
	done
	*/
